/**
 *  *2010-6-11 下午04:55:15  add 
 */
package com.base.myproject.client.HR.gcode;

import java.util.ArrayList;
import java.util.List;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.BO.BusiObject;
import com.base.myproject.client.system.BaseResource;
import com.base.myproject.client.system.Env;
import com.base.myproject.client.tools.BaseRatify;
import com.base.myproject.client.tools.CommandSyncContainer;
import com.base.myproject.client.tools.CommandSyncGetModelDatas;
import com.base.myproject.client.tools.CommandSyncReturnObject;
import com.base.myproject.client.tools.CommandSyncsql;
import com.base.myproject.client.tools.GreetingService;
import com.base.myproject.client.tools.GreetingServiceAsync;
import com.base.myproject.client.ui.BaseGrid;
import com.base.myproject.client.ui.BaseJDBCPanel;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.Style.VerticalAlignment;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.store.Store;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.Info;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.form.NumberField;
import com.extjs.gxt.ui.client.widget.form.StoreFilterField;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.layout.CenterLayout;
import com.extjs.gxt.ui.client.widget.layout.TableData;
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PushButton;

/**
 * @author Administrator
 *2010-6-11
 * javazgw@gmail.com
 */
public class Hr_goods_process extends BaseJDBCPanel{
	// Anchor a1 = new Anchor("增加物品数量",false);
//	 Anchor a2 = new Anchor("减少物品数量",false);
//	 Anchor a3 = new Anchor("归还",false);
//	 Anchor a4 = new Anchor("遗失处罚",false);
//	 Anchor a5 = new Anchor("损坏处罚",false);
//	 Anchor a6 = new Anchor("损坏处罚",false);
//	 Button a1 = new Button("增加物品数量");
//	 Button a2 = new Button("减少物品数量");
//	 Button a3 = new Button("归还");
//	 Button a4 = new Button("遗失处罚");
//	 Button a5 = new Button("损坏处罚");
//	 Button a6 = new Button("增加物品数量");
	 
	 PushButton a1 = new PushButton(
		        new Image(BaseResource.INSTANCE.ark_addfile128()));
	 PushButton a2 = new PushButton(
		        new Image(BaseResource.INSTANCE.Closed128()));
	 PushButton a3 = new PushButton(
		        new Image(BaseResource.INSTANCE.ark128()));
	 PushButton a4 = new PushButton(
		        new Image(BaseResource.INSTANCE.open_safety_box128()));
	 PushButton a5 = new PushButton(
		        new Image(BaseResource.INSTANCE.Box128()));
	 PushButton a6 = new PushButton(
		        new Image(BaseResource.INSTANCE.Box128()));
	 
	public Hr_goods_process()
	{
		init();
	}
	public void init() {
//		a1.addListener(Events.Select, getListener());
//		//a1.addClickHandler(getClickHandler());
//		a2.addListener(Events.Select, getListener());
//		a3.addListener(Events.Select, getListener());
//		a4.addListener(Events.Select, getListener());
//		a5.addListener(Events.Select, getListener());
		//a6.addClickHandler(getClickHandler());
		a1.addClickHandler(getClickHandler());
		a2.addClickHandler(getClickHandler());
		a3.addClickHandler(getClickHandler());
		a4.addClickHandler(getClickHandler());
		a5.addClickHandler(getClickHandler());
		a6.addClickHandler(getClickHandler());
		initwidget();
		
	}

	private void initwidget() {

		
		LayoutContainer panel = new LayoutContainer();
//		a1.setScale(ButtonScale.LARGE);
//		a1.setIcon(AbstractImagePrototype.create(BaseResource.INSTANCE.ark_addfile128()));
		//panel.setHeaderVisible(false);
//		panel.setAutoHeight(true);
//		panel.setAutoWidth(true);
		
		
		

		
		Label label1 = new Label("增加物品数量");
		Label label2 = new Label("减少物品数量");
		Label label6 = new Label("领用");
		Label label3 = new Label("归还");
		Label label4 = new Label("损坏赔偿");
		Label label5 = new Label("遗失赔偿");
		
		TableLayout tl = new TableLayout(6);
		TableData td = new TableData();
		td.setRowspan(1);
		td.setColspan(1);
		td.setPadding(10);
		td.setHorizontalAlign(HorizontalAlignment.LEFT);
		td.setVerticalAlign(VerticalAlignment.MIDDLE);
		
		
		panel.setLayout(tl);
		
		panel.add(a1, td);
		panel.add(label1, td);
		
		panel.add(a2, td);
		panel.add(label2, td);
		
		panel.add(a6, td);
		panel.add(label6, td);
		
		panel.add(a3, td);
		panel.add(label3, td);
		
		panel.add(a4, td);
		panel.add(label4, td);
		panel.add(a5, td);
		panel.add(label5, td);
		//panel.setHeaderVisible(false);
		panel.setSize(400, 400);
		this.setLayout(new CenterLayout() );
//		BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER);
//
//		 
//		 centerData.setMargins(new Margins(5, 5, 5, 5));  
		 this.add(panel);
		// this.add(new Button("sssss"),centerData);
		
		
	}
	
	int sync = 0;
	Listener<BaseEvent> defaultlistener;

	Listener<BaseEvent> getListener() {
		if (defaultlistener != null) {
			return defaultlistener;
		}

		defaultlistener = new Listener<BaseEvent>() {
			public void handleEvent(BaseEvent be) {
				sync++;
				try {
					if (sync == 1) {
						if (be.getType() == Events.Select) {
							if(be.getSource().equals(a1))
							{
								add();
							}
							else if(be.getSource().equals(a2))
							{
								
								del();
							
							}
								
							else if(be.getSource().equals(a3))
							{
								returnit();
							}
							else if(be.getSource().equals(a4))
							{
								lose();
							
							}
							else if(be.getSource().equals(a5))
							{
								damage();
							
							}
						}
					}
				}
					finally {
						sync--;
					}
				}

			};
			return defaultlistener;
		}
	private ClickHandler getClickHandler()
	{
		ClickHandler clickhandler = new ClickHandler()
		{

			@Override
			public void onClick(ClickEvent event) {
				if(event.getSource().equals(a1))
				{
					add();
				}
				else if(event.getSource().equals(a2))
				{
					
					del();
				}
					
				else if(event.getSource().equals(a3))
				{
					returnit();
				}
				else if(event.getSource().equals(a4))
				{
					damage();
				}
				else if(event.getSource().equals(a5))
				{
					lose();
				
				}
				else if(event.getSource().equals(a6))
				{
					getit();
				}
//				
			}
			
		};
		return clickhandler;
	}
	
	void add()
	{

		final Dialog d = new Dialog();
		d.setHeading("添加物品数量");
		d.setSize(640,430);
		
		
		final String[] goodstype =new String[]{"code","name"};
		
		
		
		
		final BaseStore<BusiObject> goodsstore = new BaseStore<BusiObject>();
		final BaseGrid<BusiObject> goodsgrid;
		CheckBoxSelectionModel<BusiObject> cbs2 = new CheckBoxSelectionModel<BusiObject>();
		List<ColumnConfig> columns2 = new ArrayList<ColumnConfig>();
		columns2.add(cbs2.getColumn());

//		ColumnConfig C1 = new ColumnConfig("code", "code", 80);
//		columns.add(C1);
		ColumnConfig goodsC2 = new ColumnConfig("code", "编码", 80);
		columns2.add(goodsC2);
		ColumnConfig goodsC7 = new ColumnConfig("name", "名称", 80);
		columns2.add(goodsC7);
		
		ColumnConfig goodsC8 = new ColumnConfig("qty", "数量", 80);
		NumberField C_num6 = new NumberField();
		C_num6.setPropertyEditorType(Integer.class);
		
		goodsC8.setEditor(new CellEditor(C_num6));
		columns2.add(goodsC8);
		
		
		ColumnConfig goodsC11 = new ColumnConfig("qtyexists", "存在数量", 80);
		columns2.add(goodsC11);
		
		ColumnConfig goodsC9 = new ColumnConfig("qtyunit", "单位", 80);
		columns2.add(goodsC9);

		ColumnModel cm2 = new ColumnModel(columns2);
		goodsgrid = new BaseGrid<BusiObject>(goodsstore, cm2, false, false);
		 cbs2.setSelectionMode(SelectionMode.MULTI);
		 goodsgrid.setSelectionModel(cbs2);
		
		 goodsgrid.setHeight(300);
		 goodsgrid.setWidth(600);
		 goodsgrid.getView().setForceFit(true);
		
		

	
		
		//---
		
		CommandSyncContainer list2 = new CommandSyncContainer();

		CommandSyncGetModelDatas csgmd2 = new CommandSyncGetModelDatas();
		csgmd2.setSqlname("hr_goods_add");
		//csgmd.putmacro("SCARDNO", s_cardno.getValue());
		list2.add(csgmd2);
		final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT
				.create(com.base.myproject.client.tools.GreetingService.class);
		greetingService2
				.SendCommandSync(
						list2,
						new AsyncCallback<CommandSyncReturnObject>() {

							@Override
							public void onFailure(
									Throwable caught) {
								MessageBox.alert("错误",
										"网络连接失败", null);

							}

							@Override
							public void onSuccess(
									CommandSyncReturnObject result) {
								if (result.isB()) {
									// BaseStore<BusiObject>
									// salarystore = new
									// BaseStore<BusiObject>();
									if (result
											.getCommandsync() instanceof CommandSyncGetModelDatas) {
										
										goodsstore.removeAll();
										goodsstore.add(((CommandSyncGetModelDatas)(result.getCommandsync())).getList(),false);
										
										goodsgrid.getView().scrollToTop();
										
									}

								} else {
									MessageBox
											.alert(
													"错误",
													""
															+ result
																	.getMessage(),
													null);

								}

							}

						});
		
		
		
		
		StoreFilterField<BusiObject> goodsfield = new StoreFilterField<BusiObject>() {
			@Override
			protected boolean doSelect(Store<BusiObject> store,
					BusiObject parent, BusiObject record, String property,
					String filter) {
	
				for (int i = 0; i < goodstype.length; i++) {

					Object name = record.get(goodstype[i]);
					
					//TODO
					if (name!=null&&name.toString().indexOf(filter.toLowerCase()) != -1) {
						return true;
					}
				}
			
				return false;
			}

			@Override
			protected void onFilter() {
				super.onFilter();

			}

		};
		goodsfield.bind(goodsstore);
		goodsfield.setWidth(200);
		
		
		LayoutContainer lc = new LayoutContainer();
		TableLayout tl = new TableLayout(2);
		tl.setCellPadding(5);
		tl.setCellSpacing(5);
		
		TableData td1 = new TableData();
		td1.setColspan(1);
		td1.setRowspan(1);
		
		TableData td2 = new TableData();
		td2.setColspan(2);
		td2.setRowspan(1);
		
		lc.setLayout(tl);
	
		lc.add(new Label("物品："),td1);
		lc.add(goodsfield,td1);
	
		lc.add(goodsgrid,td2);
		lc.setSize(640,430);
		d.add(lc);
		d.show();
		d.getButtonById(Dialog.OK).addSelectionListener(new SelectionListener<ButtonEvent>(){

			@Override
			public void componentSelected(ButtonEvent ce) {
				
				
				if(goodsgrid.getSelectionModel().getSelectedItems().size()<=0)
				{
					MessageBox.alert("警告", "你必须至少选择一项物品", null);
					return;
				}

				
				CommandSyncsql csql = new CommandSyncsql();
				
				for(BusiObject bo:goodsgrid.getSelectionModel().getSelectedItems())
				{
					String sql ="";
					sql ="insert into hr_goodsdetail (goodscode,bcode,createdate,status,qty,qtyunit,dc,mdc) values('"+bo.get("code")+"','"+Env.getEnvbcode()+"',getdate(),99,'"+bo.get("qty")+"','"+bo.get("qtyunit")+"',1,1)";
					 csql.getV().add(sql);
				}
				 CommandSyncContainer list = new CommandSyncContainer();
				 list.add(csql);
				 d.getButtonById(Dialog.OK).setEnabled(false);
				 GreetingServiceAsync greetingService = GWT
					.create(GreetingService.class);
				 greetingService
					.SendCommandSync(
							list,
							new AsyncCallback<CommandSyncReturnObject>() {
								@Override
								public void onFailure(
										Throwable caught) {
									MessageBox.alert("错误",
											"网络连接失败", null);
									d.getButtonById(Dialog.OK).setEnabled(true);
								}
								@Override
								public void onSuccess(
										CommandSyncReturnObject result) {
									if (result.isB()) {
										Info.display("", "添加成功");
									}
									else{
										MessageBox.alert("错误",
												"错误，错误代码"+result.getMessage(), null);
										d.getButtonById(Dialog.OK).setEnabled(true);
									}
								}
							});
				
			}
			
		});
	
		
	}
	
	void del()
	{



		final Dialog d = new Dialog();
		d.setHeading("减少物品数量");
		d.setSize(640,430);
		
		
		final String[] goodstype =new String[]{"code","name"};
		
		
		
		
		final BaseStore<BusiObject> goodsstore = new BaseStore<BusiObject>();
		final BaseGrid<BusiObject> goodsgrid;
		CheckBoxSelectionModel<BusiObject> cbs2 = new CheckBoxSelectionModel<BusiObject>();
		List<ColumnConfig> columns2 = new ArrayList<ColumnConfig>();
		columns2.add(cbs2.getColumn());

//		ColumnConfig C1 = new ColumnConfig("code", "code", 80);
//		columns.add(C1);
		ColumnConfig goodsC2 = new ColumnConfig("code", "编码", 80);
		columns2.add(goodsC2);
		ColumnConfig goodsC7 = new ColumnConfig("name", "名称", 80);
		columns2.add(goodsC7);
		
		ColumnConfig goodsC8 = new ColumnConfig("qty", "数量", 80);
		NumberField C_num6 = new NumberField();
		C_num6.setPropertyEditorType(Integer.class);
		
		goodsC8.setEditor(new CellEditor(C_num6));
		columns2.add(goodsC8);
		
		ColumnConfig goodsC11 = new ColumnConfig("qtyexists", "存在数量", 80);
		columns2.add(goodsC11);
		ColumnConfig goodsC9 = new ColumnConfig("qtyunit", "单位", 80);
		columns2.add(goodsC9);

		ColumnModel cm2 = new ColumnModel(columns2);
		goodsgrid = new BaseGrid<BusiObject>(goodsstore, cm2, false, false);
		 cbs2.setSelectionMode(SelectionMode.MULTI);
		 goodsgrid.setSelectionModel(cbs2);
		
		 goodsgrid.setHeight(300);
		 goodsgrid.setWidth(600);
		 goodsgrid.getView().setForceFit(true);
		
		

	
		
		//---
		
		CommandSyncContainer list2 = new CommandSyncContainer();

		CommandSyncGetModelDatas csgmd2 = new CommandSyncGetModelDatas();
		csgmd2.setSqlname("hr_goods_add");
		//csgmd.putmacro("SCARDNO", s_cardno.getValue());
		list2.add(csgmd2);
		final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT
				.create(com.base.myproject.client.tools.GreetingService.class);
		greetingService2
				.SendCommandSync(
						list2,
						new AsyncCallback<CommandSyncReturnObject>() {

							@Override
							public void onFailure(
									Throwable caught) {
								MessageBox.alert("错误",
										"网络连接失败", null);

							}

							@Override
							public void onSuccess(
									CommandSyncReturnObject result) {
								if (result.isB()) {
									// BaseStore<BusiObject>
									// salarystore = new
									// BaseStore<BusiObject>();
									if (result
											.getCommandsync() instanceof CommandSyncGetModelDatas) {
										
										goodsstore.removeAll();
										goodsstore.add(((CommandSyncGetModelDatas)(result.getCommandsync())).getList(),false);
										
										goodsgrid.getView().scrollToTop();
										
									}

								} else {
									MessageBox
											.alert(
													"错误",
													""
															+ result
																	.getMessage(),
													null);

								}

							}

						});
		
		
		
		
		StoreFilterField<BusiObject> goodsfield = new StoreFilterField<BusiObject>() {
			@Override
			protected boolean doSelect(Store<BusiObject> store,
					BusiObject parent, BusiObject record, String property,
					String filter) {
	
				for (int i = 0; i < goodstype.length; i++) {

					Object name = record.get(goodstype[i]);
					
					//TODO
					if (name!=null&&name.toString().indexOf(filter.toLowerCase()) != -1) {
						return true;
					}
				}
			
				return false;
			}

			@Override
			protected void onFilter() {
				super.onFilter();

			}

		};
		goodsfield.bind(goodsstore);
		goodsfield.setWidth(200);
		
		
		LayoutContainer lc = new LayoutContainer();
		TableLayout tl = new TableLayout(2);
		tl.setCellPadding(5);
		tl.setCellSpacing(5);
		
		TableData td1 = new TableData();
		td1.setColspan(1);
		td1.setRowspan(1);
		
		TableData td2 = new TableData();
		td2.setColspan(2);
		td2.setRowspan(1);
		
		lc.setLayout(tl);
	
		lc.add(new Label("物品："),td1);
		lc.add(goodsfield,td1);
	
		lc.add(goodsgrid,td2);
		lc.setSize(640,430);
		d.add(lc);
		d.show();
		d.getButtonById(Dialog.OK).addSelectionListener(new SelectionListener<ButtonEvent>(){

			@Override
			public void componentSelected(ButtonEvent ce) {
				
				
				if(goodsgrid.getSelectionModel().getSelectedItems().size()<=0)
				{
					MessageBox.alert("警告", "你必须至少选择一项物品", null);
					return;
				}

				
				CommandSyncsql csql = new CommandSyncsql();
				
				for(BusiObject bo:goodsgrid.getSelectionModel().getSelectedItems())
				{
					String sql ="";
					sql ="insert into hr_goodsdetail (goodscode,bcode,createdate,status,qty,qtyunit,dc,mdc) values('"+bo.get("code")+"','"+Env.getEnvbcode()+"',getdate(),100,'"+bo.get("qty")+"','"+bo.get("qtyunit")+"',-1,-1)";
					 csql.getV().add(sql);
				}
				 CommandSyncContainer list = new CommandSyncContainer();
				 list.add(csql);
				 d.getButtonById(Dialog.OK).setEnabled(false);
				 GreetingServiceAsync greetingService = GWT
					.create(GreetingService.class);
				 greetingService
					.SendCommandSync(
							list,
							new AsyncCallback<CommandSyncReturnObject>() {
								@Override
								public void onFailure(
										Throwable caught) {
									MessageBox.alert("错误",
											"网络连接失败", null);
									d.getButtonById(Dialog.OK).setEnabled(true);
								}
								@Override
								public void onSuccess(
										CommandSyncReturnObject result) {
									if (result.isB()) {
										Info.display("", "添加成功");
									}
									else{
										MessageBox.alert("错误",
												"错误，错误代码"+result.getMessage(), null);
										d.getButtonById(Dialog.OK).setEnabled(true);
									}
								}
							});
				
			}
			
		});
	
		
	
	
	}
	
	@SuppressWarnings("unchecked")
	void getit()
	{
		System.out.println("领取物品中");
		final Dialog d = new Dialog();
		d.setSize(640,430);
		
		final String[] bcodetype =new String[]{"bcode","bname"};
		final String[] goodstype =new String[]{"code","name"};
		
		final BaseStore<BusiObject> bcodestore = new BaseStore<BusiObject>();
		final BaseGrid<BusiObject> bcodegrid;
		CheckBoxSelectionModel<BusiObject> cbs = new CheckBoxSelectionModel<BusiObject>();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());

//		ColumnConfig C1 = new ColumnConfig("code", "code", 80);
//		columns.add(C1);
		ColumnConfig C2 = new ColumnConfig("bcode", "编码", 80);
		columns.add(C2);
		ColumnConfig C7 = new ColumnConfig("bname", "名称", 80);
		columns.add(C7);

		ColumnModel cm = new ColumnModel(columns);
		 bcodegrid = new BaseGrid<BusiObject>(bcodestore, cm, false, false);
		 cbs.setSelectionMode(SelectionMode.SINGLE);
		 bcodegrid.setSelectionModel(cbs);
		bcodegrid.setHeight(300);
		bcodegrid.setWidth(300);
		bcodegrid.getView().setForceFit(true);
		
		
		final BaseStore<BusiObject> goodsstore = new BaseStore<BusiObject>();
		final BaseGrid<BusiObject> goodsgrid;
		CheckBoxSelectionModel<BusiObject> cbs2 = new CheckBoxSelectionModel<BusiObject>();
		List<ColumnConfig> columns2 = new ArrayList<ColumnConfig>();
		columns2.add(cbs2.getColumn());

//		ColumnConfig C1 = new ColumnConfig("code", "code", 80);
//		columns.add(C1);
		ColumnConfig goodsC2 = new ColumnConfig("code", "编码", 80);
		columns2.add(goodsC2);
		ColumnConfig goodsC7 = new ColumnConfig("name", "名称", 80);
		columns2.add(goodsC7);
		
		ColumnConfig goodsC8 = new ColumnConfig("qty", "数量", 80);
		NumberField C_num6 = new NumberField();
		C_num6.setFireChangeEventOnSetValue(true);
		C_num6.setPropertyEditorType(Integer.class);
		
		goodsC8.setEditor(new CellEditor(C_num6));
		columns2.add(goodsC8);
		
		ColumnConfig goodsC9 = new ColumnConfig("qtyunit", "单位", 80);
		columns2.add(goodsC9);

		ColumnModel cm2 = new ColumnModel(columns2);
		goodsgrid = new BaseGrid<BusiObject>(goodsstore, cm2, false, false);
		 cbs2.setSelectionMode(SelectionMode.MULTI);
		 goodsgrid.setSelectionModel(cbs2);
		
		 goodsgrid.setHeight(300);
		 goodsgrid.setWidth(300);
		 goodsgrid.getView().setForceFit(true);
		
		

		CommandSyncContainer list = new CommandSyncContainer();

		CommandSyncGetModelDatas csgmd = new CommandSyncGetModelDatas();
		csgmd.setSqlname("hr_goods_bcode");
		//csgmd.putmacro("SCARDNO", s_cardno.getValue());
		list.add(csgmd);
		final com.base.myproject.client.tools.GreetingServiceAsync greetingService = GWT
				.create(com.base.myproject.client.tools.GreetingService.class);
		greetingService
				.SendCommandSync(
						list,
						new AsyncCallback<CommandSyncReturnObject>() {

							@Override
							public void onFailure(
									Throwable caught) {
								MessageBox.alert("错误",
										"网络连接失败", null);

							}

							@Override
							public void onSuccess(
									CommandSyncReturnObject result) {
								if (result.isB()) {
									// BaseStore<BusiObject>
									// salarystore = new
									// BaseStore<BusiObject>();
									if (result
											.getCommandsync() instanceof CommandSyncGetModelDatas) {
										
										bcodestore.removeAll();
										bcodestore.add(((CommandSyncGetModelDatas)(result.getCommandsync())).getList(),false);
										
										bcodegrid.getView().scrollToTop();
										
									}

								} else {
									MessageBox
											.alert(
													"错误",
													""
															+ result
																	.getMessage(),
													null);

								}

							}

						});
	
		
		
		//---
		
		CommandSyncContainer list2 = new CommandSyncContainer();

		CommandSyncGetModelDatas csgmd2 = new CommandSyncGetModelDatas();
		csgmd2.setSqlname("hr_goods_goods");
		//csgmd.putmacro("SCARDNO", s_cardno.getValue());
		list2.add(csgmd2);
		final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT
				.create(com.base.myproject.client.tools.GreetingService.class);
		greetingService2
				.SendCommandSync(
						list2,
						new AsyncCallback<CommandSyncReturnObject>() {

							@Override
							public void onFailure(
									Throwable caught) {
								MessageBox.alert("错误",
										"网络连接失败", null);

							}

							@Override
							public void onSuccess(
									CommandSyncReturnObject result) {
								if (result.isB()) {
									// BaseStore<BusiObject>
									// salarystore = new
									// BaseStore<BusiObject>();
									if (result
											.getCommandsync() instanceof CommandSyncGetModelDatas) {
										
										goodsstore.removeAll();
										goodsstore.add(((CommandSyncGetModelDatas)(result.getCommandsync())).getList(),false);
										
										goodsgrid.getView().scrollToTop();
										
									}

								} else {
									MessageBox
											.alert(
													"错误",
													""
															+ result
																	.getMessage(),
													null);

								}

							}

						});
		
		
		StoreFilterField<BusiObject> bcodefield = new StoreFilterField<BusiObject>() {
			@Override
			protected boolean doSelect(Store<BusiObject> store,
					BusiObject parent, BusiObject record, String property,
					String filter) {
	
				for (int i = 0; i < bcodetype.length; i++) {

					Object name = record.get(bcodetype[i]);
					
					if (name!=null&&name.toString().indexOf(filter.toLowerCase()) != -1) {
						return true;
					}
				}
			
				return false;
			}

			@Override
			protected void onFilter() {
				super.onFilter();

			}

		};
		bcodefield.bind(bcodestore);
		bcodefield.setWidth(200);
		
		StoreFilterField<BusiObject> goodsfield = new StoreFilterField<BusiObject>() {
			@Override
			protected boolean doSelect(Store<BusiObject> store,
					BusiObject parent, BusiObject record, String property,
					String filter) {
	
				for (int i = 0; i < goodstype.length; i++) {

					Object name = record.get(goodstype[i]);
					
					//TODO
					if (name!=null&&name.toString().indexOf(filter.toLowerCase()) != -1) {
						return true;
					}
				}
			
				return false;
			}

			@Override
			protected void onFilter() {
				super.onFilter();

			}

		};
		goodsfield.bind(goodsstore);
		goodsfield.setWidth(200);
		
		
		LayoutContainer lc = new LayoutContainer();
		TableLayout tl = new TableLayout(4);
		tl.setCellPadding(5);
		tl.setCellSpacing(5);
		
		TableData td1 = new TableData();
		td1.setColspan(1);
		td1.setRowspan(1);
		
		TableData td2 = new TableData();
		td2.setColspan(2);
		td2.setRowspan(1);
		
		lc.setLayout(tl);
		lc.add(new Label("人员："),td1);
		lc.add(bcodefield,td1);
		lc.add(new Label("物品："),td1);
		lc.add(goodsfield,td1);
		lc.add(bcodegrid,td2);
		lc.add(goodsgrid,td2);
		lc.setSize(640,430);
		d.add(lc);
		d.show();
		d.getButtonById(Dialog.OK).addSelectionListener(new SelectionListener<ButtonEvent>(){

			@Override
			public void componentSelected(ButtonEvent ce) {
				
//				BaseRatify.getInstance().doratify("7001", "001", "simple1");
//				if(1==1)
//				{
//					return;
//				}
				if(bcodegrid.getSelectionModel().getSelectedItem()==null)
				{
					MessageBox.alert("警告", "你必须选择一个领取人", null);
					return;
				}
				if(goodsgrid.getSelectionModel().getSelectedItems().size()<=0)
				{
					MessageBox.alert("警告", "你必须至少选择一项物品", null);
					return;
				}
				for(BusiObject bo:goodsgrid.getSelectionModel().getSelectedItems())
				{
					if(bo.get("qty")==null)
					{
						MessageBox.alert("警告", "选中的商品:"+bo.get("name")+"数量没有录入。", null);
						return;
					}
				}
				String bcodeselect  =bcodegrid.getSelectionModel().getSelectedItem().get("bcode");
				
				CommandSyncsql csql = new CommandSyncsql();
				
				for(BusiObject bo:goodsgrid.getSelectionModel().getSelectedItems())
				{
					String sql ="";
					sql ="insert into hr_goodsdetail (goodscode,bcode,createdate,status,qty,qtyunit,dc) values('"+bo.get("code")+"','"+bcodeselect+"',getdate(),1,'"+bo.get("qty")+"','"+bo.get("qtyunit")+"',-1)";
					 csql.getV().add(sql);
				}
				 CommandSyncContainer list = new CommandSyncContainer();
				 list.add(csql);
				 d.getButtonById(Dialog.OK).setEnabled(false);
				 GreetingServiceAsync greetingService = GWT
					.create(GreetingService.class);
				 greetingService
					.SendCommandSync(
							list,
							new AsyncCallback<CommandSyncReturnObject>() {
								@Override
								public void onFailure(
										Throwable caught) {
									MessageBox.alert("错误",
											"网络连接失败", null);
									d.getButtonById(Dialog.OK).setEnabled(true);
								}
								@Override
								public void onSuccess(
										CommandSyncReturnObject result) {
									if (result.isB()) {
										Info.display("", "成功");
									}
									else{
										MessageBox.alert("错误",
												"错误，错误代码"+result.getMessage(), null);
										d.getButtonById(Dialog.OK).setEnabled(true);
									}
								}
							});
				
			}
			
		});
		
		
		goodsgrid.getSelectionModel().addListener(Events.DeSelect, new Listener()
				{

					@Override
					public void handleEvent(BaseEvent be) {
						if(be instanceof SelectionChangedEvent)
						{
							int index = goodsgrid.getStore().indexOf(((SelectionChangedEvent)be).getSelectedItem());
							goodsgrid.setValue(index, "qty", "");
							
						}
					}
				});
		goodsgrid.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<BusiObject>(){

			@Override
			public void selectionChanged(SelectionChangedEvent<BusiObject> se) {
				
				//1.先清空所有被选中的值 ，用循环做
				//2重新给选中的赋值
		
				for(BusiObject bo: se.getSelection())
				{
					int index = goodsgrid.getStore().indexOf(bo);
					
					goodsgrid.setValue(index, "qty", 1);
				}
				
			}
			
		});
	
	}
	void lose()
	{
		final Dialog d = new Dialog();
		d.setHeading("遗失赔偿");
		d.setSize(774,430);
		
		final String[] bcodetype =new String[]{"bcode","bname"};
		final String[] goodstype =new String[]{"code","name"};
		
		final BaseStore<BusiObject> bcodestore = new BaseStore<BusiObject>();
		final BaseGrid<BusiObject> bcodegrid;
		CheckBoxSelectionModel<BusiObject> cbs = new CheckBoxSelectionModel<BusiObject>();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());

//		ColumnConfig C1 = new ColumnConfig("code", "code", 80);
//		columns.add(C1);
		ColumnConfig C2 = new ColumnConfig("bcode", "编码", 80);
		columns.add(C2);
		ColumnConfig C7 = new ColumnConfig("bname", "名称", 80);
		columns.add(C7);

		ColumnModel cm = new ColumnModel(columns);
		 bcodegrid = new BaseGrid<BusiObject>(bcodestore, cm, false, false);
		 cbs.setSelectionMode(SelectionMode.SINGLE);
		 bcodegrid.setSelectionModel(cbs);
		bcodegrid.setHeight(300);
		bcodegrid.setWidth(300);
		bcodegrid.getView().setForceFit(true);
		
		
		final BaseStore<BusiObject> goodsstore = new BaseStore<BusiObject>();
		final BaseGrid<BusiObject> goodsgrid;
		CheckBoxSelectionModel<BusiObject> cbs2 = new CheckBoxSelectionModel<BusiObject>();
		List<ColumnConfig> columns2 = new ArrayList<ColumnConfig>();
		columns2.add(cbs2.getColumn());
		

//		ColumnConfig C1 = new ColumnConfig("code", "code", 80);
//		columns.add(C1);
		ColumnConfig goodsC2 = new ColumnConfig("goodscode", "编码", 80);
		columns2.add(goodsC2);
		ColumnConfig goodsC7 = new ColumnConfig("name", "名称", 80);
		columns2.add(goodsC7);
		
		ColumnConfig goodsC8 = new ColumnConfig("qty", "数量", 80);
		NumberField C_num6 = new NumberField();
		C_num6.setPropertyEditorType(Integer.class);
		
		goodsC8.setEditor(new CellEditor(C_num6));
		columns2.add(goodsC8);
		
		ColumnConfig goodsC11 = new ColumnConfig("lostamount", "遗失赔偿单价", 80);
		columns2.add(goodsC11);
		
		ColumnConfig goodsC10 = new ColumnConfig("qtyused", "已领取数量", 80);
		columns2.add(goodsC10);
		ColumnConfig goodsC9 = new ColumnConfig("qtyunit", "单位", 80);
		columns2.add(goodsC9);

		ColumnModel cm2 = new ColumnModel(columns2);
		goodsgrid = new BaseGrid<BusiObject>(goodsstore, cm2, false, false);
		 cbs2.setSelectionMode(SelectionMode.MULTI);
		 goodsgrid.setSelectionModel(cbs2);
		
		 goodsgrid.setHeight(300);
		 goodsgrid.setWidth(433);
		 goodsgrid.getView().setForceFit(true);
		
		

		CommandSyncContainer list = new CommandSyncContainer();

		CommandSyncGetModelDatas csgmd = new CommandSyncGetModelDatas();
		csgmd.setSqlname("hr_goods_bcode");
		//csgmd.putmacro("SCARDNO", s_cardno.getValue());
		list.add(csgmd);
		final com.base.myproject.client.tools.GreetingServiceAsync greetingService = GWT
				.create(com.base.myproject.client.tools.GreetingService.class);
		greetingService
				.SendCommandSync(
						list,
						new AsyncCallback<CommandSyncReturnObject>() {

							@Override
							public void onFailure(
									Throwable caught) {
								MessageBox.alert("错误",
										"网络连接失败", null);

							}

							@Override
							public void onSuccess(
									CommandSyncReturnObject result) {
								if (result.isB()) {
									// BaseStore<BusiObject>
									// salarystore = new
									// BaseStore<BusiObject>();
									if (result
											.getCommandsync() instanceof CommandSyncGetModelDatas) {
										
										bcodestore.removeAll();
										bcodestore.add(((CommandSyncGetModelDatas)(result.getCommandsync())).getList(),false);
										
										bcodegrid.getView().scrollToTop();
										
									}

								} else {
									MessageBox
											.alert(
													"错误",
													""
															+ result
																	.getMessage(),
													null);

								}

							}

						});
	
		
		
		//---
	
			
		bcodegrid.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<BusiObject>(){

			@Override
			public void selectionChanged(SelectionChangedEvent<BusiObject> se) {
				
				CommandSyncContainer list2 = new CommandSyncContainer();

				CommandSyncGetModelDatas csgmd2 = new CommandSyncGetModelDatas();
				csgmd2.setSqlname("hr_goods_lost");
				if(bcodegrid.getSelectionModel().getSelectedItem()==null || bcodegrid.getSelectionModel().getSelectedItem().get("bcode")==null)
				{
					MessageBox.alert("警告", "请先选择人员", null);
					return ;
				}
					
				csgmd2.putmacro("BCODE",bcodegrid.getSelectionModel().getSelectedItem().get("bcode").toString());
				//csgmd.putmacro("SCARDNO", s_cardno.getValue());
				list2.add(csgmd2);
				final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT
						.create(com.base.myproject.client.tools.GreetingService.class);
				greetingService2
						.SendCommandSync(
								list2,
								new AsyncCallback<CommandSyncReturnObject>() {

									@Override
									public void onFailure(
											Throwable caught) {
										MessageBox.alert("错误",
												"网络连接失败", null);

									}

									@Override
									public void onSuccess(
											CommandSyncReturnObject result) {
										if (result.isB()) {
											// BaseStore<BusiObject>
											// salarystore = new
											// BaseStore<BusiObject>();
											if (result
													.getCommandsync() instanceof CommandSyncGetModelDatas) {
												
												goodsstore.removeAll();
												goodsstore.add(((CommandSyncGetModelDatas)(result.getCommandsync())).getList(),false);
												
												goodsgrid.getView().scrollToTop();
												
											}

										} else {
											MessageBox
													.alert(
															"错误",
															""
																	+ result
																			.getMessage(),
															null);

										}

									}

								});
			}
			
		});
		
		
		
		
		StoreFilterField<BusiObject> bcodefield = new StoreFilterField<BusiObject>() {
			@Override
			protected boolean doSelect(Store<BusiObject> store,
					BusiObject parent, BusiObject record, String property,
					String filter) {
	
				for (int i = 0; i < bcodetype.length; i++) {

					Object name = record.get(bcodetype[i]);
					
					if (name!=null&&name.toString().indexOf(filter.toLowerCase()) != -1) {
						return true;
					}
				}
			
				return false;
			}

			@Override
			protected void onFilter() {
				super.onFilter();

			}

		};
		bcodefield.bind(bcodestore);
		bcodefield.setWidth(200);
		
		StoreFilterField<BusiObject> goodsfield = new StoreFilterField<BusiObject>() {
			@Override
			protected boolean doSelect(Store<BusiObject> store,
					BusiObject parent, BusiObject record, String property,
					String filter) {
	
				for (int i = 0; i < goodstype.length; i++) {

					Object name = record.get(goodstype[i]);
					
					//TODO
					if (name!=null&&name.toString().indexOf(filter.toLowerCase()) != -1) {
						return true;
					}
				}
			
				return false;
			}

			@Override
			protected void onFilter() {
				super.onFilter();

			}

		};
		goodsfield.bind(goodsstore);
		goodsfield.setWidth(200);
		
		goodsgrid.getSelectionModel().addListener(Events.DeSelect, new Listener()
		{

			@Override
			public void handleEvent(BaseEvent be) {
				if(be instanceof SelectionChangedEvent)
				{
					int index = goodsgrid.getStore().indexOf(((SelectionChangedEvent)be).getSelectedItem());
					goodsgrid.setValue(index, "qty", "");
					
				}
			}
		});
goodsgrid.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<BusiObject>(){

	@Override
	public void selectionChanged(SelectionChangedEvent<BusiObject> se) {
		
		//1.先清空所有被选中的值 ，用循环做
		//2重新给选中的赋值

		for(BusiObject bo: se.getSelection())
		{
			int index = goodsgrid.getStore().indexOf(bo);
			
			goodsgrid.setValue(index, "qty", 1);
		}
		
	}
	
});
		
		LayoutContainer lc = new LayoutContainer();
		TableLayout tl = new TableLayout(4);
		tl.setCellPadding(5);
		tl.setCellSpacing(5);
		
		TableData td1 = new TableData();
		td1.setColspan(1);
		td1.setRowspan(1);
		
		TableData td2 = new TableData();
		td2.setColspan(2);
		td2.setRowspan(1);
		
		lc.setLayout(tl);
		lc.add(new Label("人员："),td1);
		lc.add(bcodefield,td1);
		lc.add(new Label("物品："),td1);
		lc.add(goodsfield,td1);
		lc.add(bcodegrid,td2);
		lc.add(goodsgrid,td2);
		lc.setSize(640,430);
		d.add(lc);
		d.show();
		d.getButtonById(Dialog.OK).addSelectionListener(new SelectionListener<ButtonEvent>(){

			@Override
			public void componentSelected(ButtonEvent ce) {
				
				if(bcodegrid.getSelectionModel().getSelectedItem()==null)
				{
					MessageBox.alert("警告", "你必须选择一个领取人", null);
					return;
				}
				if(goodsgrid.getSelectionModel().getSelectedItems().size()<=0)
				{
					MessageBox.alert("警告", "你必须至少选择一项物品", null);
					return;
				}
				for(BusiObject bo:goodsgrid.getSelectionModel().getSelectedItems())
				{
					if(bo.get("qty")==null)
					{
						MessageBox.alert("警告", "选中的商品:"+bo.get("name")+"数量没有录入。", null);
						return;
					}
					
					if(bo.get("lostamount")==null)
					{
						MessageBox.alert("警告", "选中的商品:"+bo.get("name")+"遗失赔偿单价未设置。", null);
						return;
					}
					
					if(Double.parseDouble(bo.get("qty").toString())>Double.parseDouble(bo.get("qtyused").toString()))
					{
						MessageBox.alert("警告", "选中的商品:"+bo.get("name")+"归还数量大于领取数量。", null);
						return;
					}
				}
				String bcodeselect  =bcodegrid.getSelectionModel().getSelectedItem().get("bcode");
				
				CommandSyncsql csql = new CommandSyncsql();
				
				for(BusiObject bo:goodsgrid.getSelectionModel().getSelectedItems())
				{
					String sql ="";
					sql ="insert into hr_goodsdetail (goodscode,bcode,createdate,status,qty,qtyunit,dc,lostamount,mdc) values('"+bo.get("goodscode")+"','"+bcodeselect+"',getdate(),3,'"+bo.get("qty")+"','"+bo.get("qtyunit")+"',1,"+bo.get("lostamount")+",-1)";
						 csql.getV().add(sql);
				}
				 CommandSyncContainer list = new CommandSyncContainer();
				 list.add(csql);
				 d.getButtonById(Dialog.OK).setEnabled(false);
				 GreetingServiceAsync greetingService = GWT
					.create(GreetingService.class);
				 greetingService
					.SendCommandSync(
							list,
							new AsyncCallback<CommandSyncReturnObject>() {
								@Override
								public void onFailure(
										Throwable caught) {
									MessageBox.alert("错误",
											"网络连接失败", null);
									d.getButtonById(Dialog.OK).setEnabled(true);
								}
								@Override
								public void onSuccess(
										CommandSyncReturnObject result) {
									if (result.isB()) {
										Info.display("", "成功");
									}
									else{
										MessageBox.alert("错误",
												"错误，错误代码"+result.getMessage(), null);
										d.getButtonById(Dialog.OK).setEnabled(true);
									}
								}
							});
				
			}
			
		});
	
		
	
	
	}
	void returnit()
	{


		final Dialog d = new Dialog();
		d.setHeading("归还物品");
		d.setSize(774,430);
		
		final String[] bcodetype =new String[]{"bcode","bname"};
		final String[] goodstype =new String[]{"code","name"};
		
		final BaseStore<BusiObject> bcodestore = new BaseStore<BusiObject>();
		final BaseGrid<BusiObject> bcodegrid;
		CheckBoxSelectionModel<BusiObject> cbs = new CheckBoxSelectionModel<BusiObject>();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());

//		ColumnConfig C1 = new ColumnConfig("code", "code", 80);
//		columns.add(C1);
		ColumnConfig C2 = new ColumnConfig("bcode", "编码", 80);
		columns.add(C2);
		ColumnConfig C7 = new ColumnConfig("bname", "名称", 80);
		columns.add(C7);

		ColumnModel cm = new ColumnModel(columns);
		 bcodegrid = new BaseGrid<BusiObject>(bcodestore, cm, false, false);
		 cbs.setSelectionMode(SelectionMode.SINGLE);
		 bcodegrid.setSelectionModel(cbs);
		bcodegrid.setHeight(300);
		bcodegrid.setWidth(300);
		bcodegrid.getView().setForceFit(true);
		
		
		final BaseStore<BusiObject> goodsstore = new BaseStore<BusiObject>();
		final BaseGrid<BusiObject> goodsgrid;
		CheckBoxSelectionModel<BusiObject> cbs2 = new CheckBoxSelectionModel<BusiObject>();
		List<ColumnConfig> columns2 = new ArrayList<ColumnConfig>();
		columns2.add(cbs2.getColumn());

//		ColumnConfig C1 = new ColumnConfig("code", "code", 80);
//		columns.add(C1);
		ColumnConfig goodsC2 = new ColumnConfig("goodscode", "编码", 80);
		columns2.add(goodsC2);
		ColumnConfig goodsC7 = new ColumnConfig("name", "名称", 80);
		columns2.add(goodsC7);
		
		ColumnConfig goodsC8 = new ColumnConfig("qty", "数量", 80);
		NumberField C_num6 = new NumberField();
		C_num6.setPropertyEditorType(Integer.class);
		
		goodsC8.setEditor(new CellEditor(C_num6));
		columns2.add(goodsC8);
		
		
		ColumnConfig goodsC10 = new ColumnConfig("qtyused", "已领取数量", 80);
		columns2.add(goodsC10);
		ColumnConfig goodsC9 = new ColumnConfig("qtyunit", "单位", 80);
		columns2.add(goodsC9);

		ColumnModel cm2 = new ColumnModel(columns2);
		goodsgrid = new BaseGrid<BusiObject>(goodsstore, cm2, false, false);
		 cbs2.setSelectionMode(SelectionMode.MULTI);
		 goodsgrid.setSelectionModel(cbs2);

		 goodsgrid.setHeight(300);
		 goodsgrid.setWidth(433);
		 goodsgrid.getView().setForceFit(true);
		
		

		CommandSyncContainer list = new CommandSyncContainer();

		CommandSyncGetModelDatas csgmd = new CommandSyncGetModelDatas();
		csgmd.setSqlname("hr_goods_bcode");
		//csgmd.putmacro("SCARDNO", s_cardno.getValue());
		list.add(csgmd);
		final com.base.myproject.client.tools.GreetingServiceAsync greetingService = GWT
				.create(com.base.myproject.client.tools.GreetingService.class);
		greetingService
				.SendCommandSync(
						list,
						new AsyncCallback<CommandSyncReturnObject>() {

							@Override
							public void onFailure(
									Throwable caught) {
								MessageBox.alert("错误",
										"网络连接失败", null);

							}

							@Override
							public void onSuccess(
									CommandSyncReturnObject result) {
								if (result.isB()) {
									// BaseStore<BusiObject>
									// salarystore = new
									// BaseStore<BusiObject>();
									if (result
											.getCommandsync() instanceof CommandSyncGetModelDatas) {
										
										bcodestore.removeAll();
										bcodestore.add(((CommandSyncGetModelDatas)(result.getCommandsync())).getList(),false);
										
										bcodegrid.getView().scrollToTop();
										
									}

								} else {
									MessageBox
											.alert(
													"错误",
													""
															+ result
																	.getMessage(),
													null);

								}

							}

						});
	
		
		
		//---
		bcodegrid.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<BusiObject>(){

			@Override
			public void selectionChanged(SelectionChangedEvent<BusiObject> se) {
				
				CommandSyncContainer list2 = new CommandSyncContainer();

				CommandSyncGetModelDatas csgmd2 = new CommandSyncGetModelDatas();
				csgmd2.setSqlname("hr_goods_return");
				if(bcodegrid.getSelectionModel().getSelectedItem()==null || bcodegrid.getSelectionModel().getSelectedItem().get("bcode")==null)
				{
					MessageBox.alert("警告", "请先选择人员", null);
					return ;
				}
					
				csgmd2.putmacro("BCODE",bcodegrid.getSelectionModel().getSelectedItem().get("bcode").toString());
				//csgmd.putmacro("SCARDNO", s_cardno.getValue());
				list2.add(csgmd2);
				final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT
						.create(com.base.myproject.client.tools.GreetingService.class);
				greetingService2
						.SendCommandSync(
								list2,
								new AsyncCallback<CommandSyncReturnObject>() {

									@Override
									public void onFailure(
											Throwable caught) {
										MessageBox.alert("错误",
												"网络连接失败", null);

									}

									@Override
									public void onSuccess(
											CommandSyncReturnObject result) {
										if (result.isB()) {
											// BaseStore<BusiObject>
											// salarystore = new
											// BaseStore<BusiObject>();
											if (result
													.getCommandsync() instanceof CommandSyncGetModelDatas) {
												
												goodsstore.removeAll();
												goodsstore.add(((CommandSyncGetModelDatas)(result.getCommandsync())).getList(),false);
												
												goodsgrid.getView().scrollToTop();
												
											}

										} else {
											MessageBox
													.alert(
															"错误",
															""
																	+ result
																			.getMessage(),
															null);

										}

									}

								});
			}
			
		});
		
		StoreFilterField<BusiObject> bcodefield = new StoreFilterField<BusiObject>() {
			@Override
			protected boolean doSelect(Store<BusiObject> store,
					BusiObject parent, BusiObject record, String property,
					String filter) {
	
				for (int i = 0; i < bcodetype.length; i++) {

					Object name = record.get(bcodetype[i]);
					
					if (name!=null&&name.toString().indexOf(filter.toLowerCase()) != -1) {
						return true;
					}
				}
			
				return false;
			}

			@Override
			protected void onFilter() {
				super.onFilter();

			}

		};
		bcodefield.bind(bcodestore);
		bcodefield.setWidth(200);
		
		StoreFilterField<BusiObject> goodsfield = new StoreFilterField<BusiObject>() {
			@Override
			protected boolean doSelect(Store<BusiObject> store,
					BusiObject parent, BusiObject record, String property,
					String filter) {
	
				for (int i = 0; i < goodstype.length; i++) {

					Object name = record.get(goodstype[i]);
					
					//TODO
					if (name!=null&&name.toString().indexOf(filter.toLowerCase()) != -1) {
						return true;
					}
				}
			
				return false;
			}

			@Override
			protected void onFilter() {
				super.onFilter();

			}

		};
		goodsfield.bind(goodsstore);
		goodsfield.setWidth(200);
		
		goodsgrid.getSelectionModel().addListener(Events.DeSelect, new Listener()
		{

			@Override
			public void handleEvent(BaseEvent be) {
				if(be instanceof SelectionChangedEvent)
				{
					int index = goodsgrid.getStore().indexOf(((SelectionChangedEvent)be).getSelectedItem());
					goodsgrid.setValue(index, "qty", "");
					
				}
			}
		});
		goodsgrid.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<BusiObject>(){
		
			@Override
			public void selectionChanged(SelectionChangedEvent<BusiObject> se) {
				for(BusiObject bo: se.getSelection())
				{
					int index = goodsgrid.getStore().indexOf(bo);
					
					goodsgrid.setValue(index, "qty",bo.get("qtyused"));
				}
				
			}
			
		});
		LayoutContainer lc = new LayoutContainer();
		TableLayout tl = new TableLayout(4);
		tl.setCellPadding(5);
		tl.setCellSpacing(5);
		
		TableData td1 = new TableData();
		td1.setColspan(1);
		td1.setRowspan(1);
		
		TableData td2 = new TableData();
		td2.setColspan(2);
		td2.setRowspan(1);
		
		lc.setLayout(tl);
		lc.add(new Label("人员："),td1);
		lc.add(bcodefield,td1);
		lc.add(new Label("物品："),td1);
		lc.add(goodsfield,td1);
		lc.add(bcodegrid,td2);
		lc.add(goodsgrid,td2);
		lc.setSize(640,430);
		d.add(lc);
		d.show();
		d.getButtonById(Dialog.OK).addSelectionListener(new SelectionListener<ButtonEvent>(){

			@Override
			public void componentSelected(ButtonEvent ce) {
				
				if(bcodegrid.getSelectionModel().getSelectedItem()==null)
				{
					MessageBox.alert("警告", "你必须选择一个领取人", null);
					return;
				}
				if(goodsgrid.getSelectionModel().getSelectedItems().size()<=0)
				{
					MessageBox.alert("警告", "你必须至少选择一项物品", null);
					return;
				}
				for(BusiObject bo:goodsgrid.getSelectionModel().getSelectedItems())
				{
					if(bo.get("qty")==null)
					{
						MessageBox.alert("警告", "选中的商品:"+bo.get("name")+"数量没有录入。", null);
						return;
					}
					
					if(Double.parseDouble(bo.get("qty").toString())>Double.parseDouble(bo.get("qtyused").toString()))
					{
						MessageBox.alert("警告", "选中的商品:"+bo.get("name")+"归还数量大于领取数量。", null);
						return;
					}
				}
				String bcodeselect  =bcodegrid.getSelectionModel().getSelectedItem().get("bcode");
				
				CommandSyncsql csql = new CommandSyncsql();
				
				for(BusiObject bo:goodsgrid.getSelectionModel().getSelectedItems())
				{
					String sql ="";
					sql ="insert into hr_goodsdetail (goodscode,bcode,createdate,status,qty,qtyunit,dc,mdc) values('"+bo.get("goodscode")+"','"+bcodeselect+"',getdate(),2,'"+bo.get("qty")+"','"+bo.get("qtyunit")+"',1,1)";
						 csql.getV().add(sql);
				
				}
				 CommandSyncContainer list = new CommandSyncContainer();
				 list.add(csql);
				 d.getButtonById(Dialog.OK).setEnabled(false);
				 GreetingServiceAsync greetingService = GWT
					.create(GreetingService.class);
				 greetingService
					.SendCommandSync(
							list,
							new AsyncCallback<CommandSyncReturnObject>() {
								@Override
								public void onFailure(
										Throwable caught) {
									MessageBox.alert("错误",
											"网络连接失败", null);
									d.getButtonById(Dialog.OK).setEnabled(true);
								}
								@Override
								public void onSuccess(
										CommandSyncReturnObject result) {
									if (result.isB()) {
										Info.display("", "归还成功");
									}
									else{
										MessageBox.alert("错误",
												"错误，错误代码"+result.getMessage(), null);
										d.getButtonById(Dialog.OK).setEnabled(true);
									}
								}
							});
				
			}
			
		});
	
		
	
	}
	void damage()
	{




		final Dialog d = new Dialog();
		d.setHeading("损坏赔偿");
		d.setSize(774,430);
		
		final String[] bcodetype =new String[]{"bcode","bname"};
		final String[] goodstype =new String[]{"code","name"};
		
		final BaseStore<BusiObject> bcodestore = new BaseStore<BusiObject>();
		final BaseGrid<BusiObject> bcodegrid;
		CheckBoxSelectionModel<BusiObject> cbs = new CheckBoxSelectionModel<BusiObject>();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());

//		ColumnConfig C1 = new ColumnConfig("code", "code", 80);
//		columns.add(C1);
		ColumnConfig C2 = new ColumnConfig("bcode", "编码", 80);
		columns.add(C2);
		ColumnConfig C7 = new ColumnConfig("bname", "名称", 80);
		columns.add(C7);

		ColumnModel cm = new ColumnModel(columns);
		 bcodegrid = new BaseGrid<BusiObject>(bcodestore, cm, false, false);
		 cbs.setSelectionMode(SelectionMode.SINGLE);
		 bcodegrid.setSelectionModel(cbs);
		bcodegrid.setHeight(300);
		bcodegrid.setWidth(300);
		bcodegrid.getView().setForceFit(true);
		
		
		final BaseStore<BusiObject> goodsstore = new BaseStore<BusiObject>();
		final BaseGrid<BusiObject> goodsgrid;
		CheckBoxSelectionModel<BusiObject> cbs2 = new CheckBoxSelectionModel<BusiObject>();
		List<ColumnConfig> columns2 = new ArrayList<ColumnConfig>();
		columns2.add(cbs2.getColumn());

//		ColumnConfig C1 = new ColumnConfig("code", "code", 80);
//		columns.add(C1);
		ColumnConfig goodsC2 = new ColumnConfig("goodscode", "编码", 80);
		columns2.add(goodsC2);
		ColumnConfig goodsC7 = new ColumnConfig("name", "名称", 80);
		columns2.add(goodsC7);
		
		ColumnConfig goodsC8 = new ColumnConfig("qty", "数量", 80);
		NumberField C_num6 = new NumberField();
		C_num6.setPropertyEditorType(Integer.class);
		
		goodsC8.setEditor(new CellEditor(C_num6));
		columns2.add(goodsC8);
		
		ColumnConfig goodsC11 = new ColumnConfig("damageamount", "损坏赔偿单价", 80);
		columns2.add(goodsC11);
		
		ColumnConfig goodsC10 = new ColumnConfig("qtyused", "已领取数量", 80);
		columns2.add(goodsC10);
		ColumnConfig goodsC9 = new ColumnConfig("qtyunit", "单位", 80);
		columns2.add(goodsC9);

		ColumnModel cm2 = new ColumnModel(columns2);
		goodsgrid = new BaseGrid<BusiObject>(goodsstore, cm2, false, false);
		 cbs2.setSelectionMode(SelectionMode.MULTI);
		 goodsgrid.setSelectionModel(cbs2);
		
		 goodsgrid.setHeight(300);
		 goodsgrid.setWidth(443);
		 goodsgrid.getView().setForceFit(true);
		
		 goodsgrid.getSelectionModel().addListener(Events.DeSelect, new Listener()
			{

				@Override
				public void handleEvent(BaseEvent be) {
					if(be instanceof SelectionChangedEvent)
					{
						int index = goodsgrid.getStore().indexOf(((SelectionChangedEvent)be).getSelectedItem());
						goodsgrid.setValue(index, "qty", "");
						
					}
				}
			});
			goodsgrid.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<BusiObject>(){
			
				@Override
				public void selectionChanged(SelectionChangedEvent<BusiObject> se) {
					for(BusiObject bo: se.getSelection())
					{
						int index = goodsgrid.getStore().indexOf(bo);
						
						goodsgrid.setValue(index, "qty",bo.get("qtyused"));
					}
					
				}
				
			});
		 
		CommandSyncContainer list = new CommandSyncContainer();

		CommandSyncGetModelDatas csgmd = new CommandSyncGetModelDatas();
		csgmd.setSqlname("hr_goods_bcode");
		//csgmd.putmacro("SCARDNO", s_cardno.getValue());
		list.add(csgmd);
		final com.base.myproject.client.tools.GreetingServiceAsync greetingService = GWT
				.create(com.base.myproject.client.tools.GreetingService.class);
		greetingService
				.SendCommandSync(
						list,
						new AsyncCallback<CommandSyncReturnObject>() {

							@Override
							public void onFailure(
									Throwable caught) {
								MessageBox.alert("错误",
										"网络连接失败", null);

							}

							@Override
							public void onSuccess(
									CommandSyncReturnObject result) {
								if (result.isB()) {
									// BaseStore<BusiObject>
									// salarystore = new
									// BaseStore<BusiObject>();
									if (result
											.getCommandsync() instanceof CommandSyncGetModelDatas) {
										
										bcodestore.removeAll();
										bcodestore.add(((CommandSyncGetModelDatas)(result.getCommandsync())).getList(),false);
										
										bcodegrid.getView().scrollToTop();
										
									}

								} else {
									MessageBox
											.alert(
													"错误",
													""
															+ result
																	.getMessage(),
													null);

								}

							}

						});
	
		
		
		//---
	
			
		bcodegrid.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<BusiObject>(){

			@Override
			public void selectionChanged(SelectionChangedEvent<BusiObject> se) {
				
				CommandSyncContainer list2 = new CommandSyncContainer();

				CommandSyncGetModelDatas csgmd2 = new CommandSyncGetModelDatas();
				csgmd2.setSqlname("hr_goods_damage");
				if(bcodegrid.getSelectionModel().getSelectedItem()==null || bcodegrid.getSelectionModel().getSelectedItem().get("bcode")==null)
				{
					MessageBox.alert("警告", "请先选择人员", null);
					return ;
				}
					
				csgmd2.putmacro("BCODE",bcodegrid.getSelectionModel().getSelectedItem().get("bcode").toString());
				//csgmd.putmacro("SCARDNO", s_cardno.getValue());
				list2.add(csgmd2);
				final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT
						.create(com.base.myproject.client.tools.GreetingService.class);
				greetingService2
						.SendCommandSync(
								list2,
								new AsyncCallback<CommandSyncReturnObject>() {

									@Override
									public void onFailure(
											Throwable caught) {
										MessageBox.alert("错误",
												"网络连接失败", null);

									}

									@Override
									public void onSuccess(
											CommandSyncReturnObject result) {
										if (result.isB()) {
											// BaseStore<BusiObject>
											// salarystore = new
											// BaseStore<BusiObject>();
											if (result
													.getCommandsync() instanceof CommandSyncGetModelDatas) {
												
												goodsstore.removeAll();
												goodsstore.add(((CommandSyncGetModelDatas)(result.getCommandsync())).getList(),false);
												
												goodsgrid.getView().scrollToTop();
												
											}

										} else {
											MessageBox
													.alert(
															"错误",
															""
																	+ result
																			.getMessage(),
															null);

										}

									}

								});
			}
			
		});
		
		
		
		
		StoreFilterField<BusiObject> bcodefield = new StoreFilterField<BusiObject>() {
			@Override
			protected boolean doSelect(Store<BusiObject> store,
					BusiObject parent, BusiObject record, String property,
					String filter) {
	
				for (int i = 0; i < bcodetype.length; i++) {

					Object name = record.get(bcodetype[i]);
					
					if (name!=null&&name.toString().indexOf(filter.toLowerCase()) != -1) {
						return true;
					}
				}
			
				return false;
			}

			@Override
			protected void onFilter() {
				super.onFilter();

			}

		};
		bcodefield.bind(bcodestore);
		bcodefield.setWidth(200);
		
		StoreFilterField<BusiObject> goodsfield = new StoreFilterField<BusiObject>() {
			@Override
			protected boolean doSelect(Store<BusiObject> store,
					BusiObject parent, BusiObject record, String property,
					String filter) {
	
				for (int i = 0; i < goodstype.length; i++) {

					Object name = record.get(goodstype[i]);
					
					//TODO
					if (name!=null&&name.toString().indexOf(filter.toLowerCase()) != -1) {
						return true;
					}
				}
			
				return false;
			}

			@Override
			protected void onFilter() {
				super.onFilter();

			}

		};
		goodsfield.bind(goodsstore);
		goodsfield.setWidth(200);
		
		
		LayoutContainer lc = new LayoutContainer();
		TableLayout tl = new TableLayout(4);
		tl.setCellPadding(5);
		tl.setCellSpacing(5);
		
		TableData td1 = new TableData();
		td1.setColspan(1);
		td1.setRowspan(1);
		
		TableData td2 = new TableData();
		td2.setColspan(2);
		td2.setRowspan(1);
		
		lc.setLayout(tl);
		lc.add(new Label("人员："),td1);
		lc.add(bcodefield,td1);
		lc.add(new Label("物品："),td1);
		lc.add(goodsfield,td1);
		lc.add(bcodegrid,td2);
		lc.add(goodsgrid,td2);
		lc.setSize(640,430);
		d.add(lc);
		d.show();
		d.getButtonById(Dialog.OK).addSelectionListener(new SelectionListener<ButtonEvent>(){

			@Override
			public void componentSelected(ButtonEvent ce) {
				
				if(bcodegrid.getSelectionModel().getSelectedItem()==null)
				{
					MessageBox.alert("警告", "你必须选择一个领取人", null);
					return;
				}
				if(goodsgrid.getSelectionModel().getSelectedItems().size()<=0)
				{
					MessageBox.alert("警告", "你必须至少选择一项物品", null);
					return;
				}
				for(BusiObject bo:goodsgrid.getSelectionModel().getSelectedItems())
				{
					if(bo.get("qty")==null)
					{
						MessageBox.alert("警告", "选中的商品:"+bo.get("name")+"数量没有录入。", null);
						return;
					}
					
					if(bo.get("damageamount")==null)
					{
						MessageBox.alert("警告", "选中的商品:"+bo.get("name")+"损坏赔偿单价未设置。", null);
						return;
					}
					
					if(Double.parseDouble(bo.get("qty").toString())>Double.parseDouble(bo.get("qtyused").toString()))
					{
						MessageBox.alert("警告", "选中的商品:"+bo.get("name")+"归还数量大于领取数量。", null);
						return;
					}
				}
				String bcodeselect  =bcodegrid.getSelectionModel().getSelectedItem().get("bcode");
				
				CommandSyncsql csql = new CommandSyncsql();
				
				for(BusiObject bo:goodsgrid.getSelectionModel().getSelectedItems())
				{
					String sql ="";
					sql ="insert into hr_goodsdetail (goodscode,bcode,createdate,status,qty,qtyunit,dc,damageamount,mdc) values('"+bo.get("goodscode")+"','"+bcodeselect+"',getdate(),4,'"+bo.get("qty")+"','"+bo.get("qtyunit")+"',1,"+bo.get("damageamount")+",-1)";
						 csql.getV().add(sql);
				}
				 CommandSyncContainer list = new CommandSyncContainer();
				 list.add(csql);
				 d.getButtonById(Dialog.OK).setEnabled(false);
				 GreetingServiceAsync greetingService = GWT
					.create(GreetingService.class);
				 greetingService
					.SendCommandSync(
							list,
							new AsyncCallback<CommandSyncReturnObject>() {
								@Override
								public void onFailure(
										Throwable caught) {
									MessageBox.alert("错误",
											"网络连接失败", null);
									d.getButtonById(Dialog.OK).setEnabled(true);
								}
								@Override
								public void onSuccess(
										CommandSyncReturnObject result) {
									if (result.isB()) {
										Info.display("", "成功");
									}
									else{
										MessageBox.alert("错误",
												"错误，错误代码"+result.getMessage(), null);
										d.getButtonById(Dialog.OK).setEnabled(true);
									}
								}
							});
				
			}
			
		});
	
		
	
	
	
	}
}
